﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string StrNum1, StrNum2;
            int IntNum1, IntNum2;
            int IntRit = 0;

            while (true)
            {
                try
                {
                    // 1、键盘输入Console.Read
                    Console.Write("请输入第一个数字：");
                    StrNum1 = Console.ReadLine();
                    //2、类型转换 type.Parse Convert.ToType(type)var as(is) var.ToString()
                    IntNum1 = int.Parse(StrNum1);
                    break;
                }
                catch
                {
                    Console.Clear();
                }
            }

            Console.Write("请输入运算符：");
            string StrOp = Console.ReadLine();

            while (true)
            {
                try
                {
                    // 1、键盘输入Console.Read
                    Console.Write("请输入第二个数字：");
                    StrNum2 = Console.ReadLine();
                    //2、类型转换 type.Parse Convert.ToType(type)var as(is) var.ToString()
                    IntNum2 = Convert.ToInt32(StrNum2);
                    break;
                }
                catch
                {
                    Console.Clear();
                }
            }

            //3、分支语句判断运算类型 if switch
            switch (StrOp)
            {
                case "+":
                    IntRit = IntNum1 + IntNum2;
                    break;
                case "-":
                    IntRit = IntNum1 - IntNum2;
                    break;
                case "*":
                    IntRit = IntNum1 * IntNum2;
                    break;
                case "/":
                    try
                    {
                        IntRit = IntNum1 / IntNum2;  
                    }
                    catch
                    {
                        Console.Clear();
                    }
                    break;
            }

            //4、输出运算结果（转换）Consloe.Wirte x + y = z
            Console.Write("运算结果：");
            string fmt = "{0}{1}{2}={3} \r\n {0}{1}{2}={3}";
            //Console.WriteLine(fmt, IntNum1, StrOp, IntNum2, IntRit);
            Console.Write(IntNum1.ToString() + StrOp + IntNum2.ToString() + "=" + IntRit.ToString());
            Console.Read();
        }
    }
}
